﻿namespace UFIDA.U9.CUST.AITBarCodeBP
{
	using System;
	using System.Collections.Generic;
    using System.Text;
    using UFIDA.U9.CUST.AITBarCodeBE;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;

	/// <summary>
	/// UpdateBarCode partial 
	/// </summary>	
	public partial class UpdateBarCode 
	{	
		internal BaseStrategy Select()
		{
			return new UpdateBarCodeImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class UpdateBarCodeImpementStrategy : BaseStrategy
	{
		public UpdateBarCodeImpementStrategy() { }

		public override object Do(object obj)
		{						
			UpdateBarCode bpObj = (UpdateBarCode)obj;

			if (bpObj.IDS == null || bpObj.IDS.Count == 0)
				throw new Exception("传入IDS为空");


			foreach (var id in bpObj.IDS)
			{
				//为避免生成重复条码,需要在循环内session
				using (ISession session = Session.Open())
				{
					AITBarCode be = AITBarCode.Finder.FindByID(id);
					if (be == null) throw new Exception("查询条码实体失败!");

					if (string.IsNullOrEmpty(be.BarCode))
					{
						GetBarCode bp = new GetBarCode();
						bp.ID = id;
						string barcode = bp.Do();
						be.BarCode = barcode;//更新条码
						be.BarQty = be.Qty;//记录生成条码时的数量
					}
					session.Commit();
				}
			}
			return bpObj.IDS;
		}		
	}

	#endregion
	
	
}